package com.carltechnology.mahjonggamecaculation.dao.impl;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by WZTCM on 2016/6/28.
 * The SqliteOpenHelper class.
 */
public class MahjongGameSqliteHelper extends SQLiteOpenHelper {
        enum DATABASE_INFO {
        DB_NAME("mahjong.db"),
        TABLE_GAMEDATA_NAME("game"),
        TABLE_DETAILDATA_NAME("gamedetail"),
        TABLE_RUNTIME_NAME("runtime"),
        CREATE_MAHJONGTABLE("create table game ("
                + "id INTEGER PRIMARY KEY   AUTOINCREMENT,"
                + "name text not null,"
                + "date text not null)"),

        //        MAHJONGGAME_TABLE1("name"),
        //        MAHJONGGAME_TABLE2("date"),
//        INSERT_HKL("insert into game (id,name,date) values('123213','hkl_ct_wx_sj','1992-10-12')"),
//        INSERT("insert into gamedetail(id,income1,income2,income3,income4,cost,perunit,date)" +
//                " values(123213,100,200,300,100,20,2,'1992-10-12')"),
//            INSERT_2("insert into gamedetail(id,income1,income2,income3,income4,cost,perunit,date)" +
//                    " values(123213,100,200,300,100,20,2,'1992-10-12')"),
//            INSERT_3("insert into gamedetail(id,income1,income2,income3,income4,cost,perunit,date)" +
//                    " values(123213,100,200,300,100,20,2,'1992-10-12')"),
        CREATE_MAHJONGGAME_DETAIL("create table gamedetail ("
                + "id INTEGER ," +
                "income1 integer not null," +
                "income2 integer not null," +
                "income3 integer not null," +
                "income4 integer not null," +
                "cost integer not null," +
                "perunit integer not null," +
                "date text not null)"),
        CREATE_RUNTIME("create table runtime (" +
                "id INTEGER PRIMARY KEY ," +
                "count1 integer not null," +
                "count2 integer not null," +
                "count3 integer not null," +
                "count4 integer not null," +
                "cost integer not null," +
                "mcount integer not null)"
        );
        private String string;
        DATABASE_INFO(String string) {
            this.string = string;
        }
        @Override
        public String toString() {
            return string;
        }
    }

    private Context mContext;

    public MahjongGameSqliteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(String.valueOf(DATABASE_INFO.CREATE_MAHJONGTABLE));
        db.execSQL(String.valueOf(DATABASE_INFO.CREATE_MAHJONGGAME_DETAIL));
        db.execSQL(String.valueOf(DATABASE_INFO.CREATE_RUNTIME));
        Toast.makeText(mContext, "SQL SUCCESSED", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
    public String getGameTableName(){
        return DATABASE_INFO.TABLE_GAMEDATA_NAME.toString();
    }
    public String getDetailGameTableName(){
        return DATABASE_INFO.TABLE_DETAILDATA_NAME.toString();

    }
    public String getRuntimeTableName(){
        return DATABASE_INFO.TABLE_RUNTIME_NAME.toString();
    }
}
